package com.hwtx.form.persistence;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwtx.form.domain.repo.I18nRepo;
import com.hwtx.form.persistence.entity.I18nMessage;
import com.hwtx.form.persistence.mapper.I18nMapper;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import static com.hwtx.form.domain.FormConstants.I18n_CACHE_KEY;

@Repository
public class I18nRepoImpl extends ServiceImpl<I18nMapper, I18nMessage> implements I18nRepo {

    @Resource
    private I18nMapper i18nMapper;

    @Cacheable(value = I18n_CACHE_KEY, key = "#code")
    @Override
    public I18nMessage getI18nMessage(String code) {
        LambdaQueryWrapper<I18nMessage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(I18nMessage::getMessageKey, code);
        return i18nMapper.selectOne(queryWrapper);
    }
}
